package com.zmf.demo.controller;

import com.zmf.demo.Result;
import com.zmf.demo.pojo.entity.Student;
import com.zmf.demo.pojo.vo.StudentVo;
import com.zmf.demo.service.StudentService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("student")
public class StudentController {
    @Resource
    private StudentService studentService;


    @PostMapping("mn/{current}/{page}")
    @ApiOperation(value = "根据条件分页")
    public Result select(@ApiParam(value = "当前页面",name ="current",required = true,defaultValue = "1")
                             @PathVariable Integer current,
                         @ApiParam(value = "每页条数",name ="page",required = true,defaultValue = "5")
                             @PathVariable Integer page,
                         @RequestBody StudentVo studentVo){

        return studentService.selectbypage(current, page, studentVo);
    }

    @PostMapping("insert")
    @ApiOperation(value = "插入单行数据")
    public Result insert(
            @ApiParam(value = "当前数据",name = "student" , required = true )
            @RequestBody Student student){

        return studentService.insert(student);
    }


    @PutMapping("update")
    @ApiOperation(value = "修改单行数据")
    public Result update(
            @ApiParam(value = "当前数据",name = "student" , required = true )
            @RequestBody Student student){

        return studentService.update(student);
    }
    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除单行数据")
    public Result delete(
            @ApiParam(value = "需要删除行的id",name = "id" , required = true )
            @PathVariable Integer id){
        return studentService.delete(id);
    }

    @GetMapping("selectbyid/{id}")
    @ApiOperation(value = "根据id查询数据")
    public Result selectbyid(
            @ApiParam(value = "需要查询行的id",name = "id" , required = true )
            @PathVariable Integer id){
        return studentService.selectbyid(id);
    }

}
